<?php
class PHZ_Memcache
{
    /**
     * 把用户的所有本局房间游戏信息全部写到缓存中
     * @param $room_id
     * @param $room_js
     * @param $user_id
     * @param $key
     * @param $value
     * @return mixed
     */
    public static function __set_userAllLog_DATA( $room_id , $room_js , $user_id  ){
        $where   = "log_to_uid = ". $user_id ." and log_rid = " . $room_id . " AND log_jid = " . $room_js;
        $logInfo = Events::$db->select('*')->from( PHZ_Log::__gTn( $room_id ) )->where( $where )->query();
        $mem_key = "log_" . $room_id . "_" . $room_js . "_" . $user_id;
        return Events::$memdb->set( $mem_key , json_encode( $logInfo ) , 0 , 2592000 );//30天有效
    }

    public static function __getgNlog_DATA( $room_id , $room_js , $user_id ){
        $mem_key  = "log_" . $room_id . "_" . $room_js . "_" . $user_id;
        return Events::$memdb->get( $mem_key );
    }

    /**
     * 设置跟查询房间信息缓存
     * @param $room_info
     * @param bool $dissolution
     * @return mixed
     */

    public static function __set_RoomInfo_ToMemcache( $room_info , $dissolution = false ){
        $mem_key = "room_" . $room_info['room_id'];
        if( $dissolution == false ){
            return Events::$memdb->set( $mem_key , json_encode( $room_info ) , 0 , 2592000 );//30天有效
        }else{
            return Events::$memdb->set( $mem_key , "null" , 0 , 5 );//5秒有效，其实也就是让他过期
        }
    }

    public static function __get_RoomInfo_ToMemcache( $room_id ){
        return Events::$memdb->get( "room_" . $room_id );
    }

}